<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>json字符串解析</title>
		<script src="js/jquery.min.js"></script>
	</head>
	<body>
		<div id="rtnData">返回数据：</div>
		<div id="itemPrice">商品价格：</div>
		<div id="itemId">商品编号：</div>
	</body>

	<script>
		var jsonstr = '[{"p":"3999.00","op":"3999.00","cbf":"0","id":"J_100007851351","m":"4000.00"}]';
		//把json字符串变成JavaScript对象
		var data = JSON.parse(jsonstr);
		

		$("#rtnData").text(jsonstr); //text()方法相当于div.innnerText
		//回显获得的数据，把对象转json字符串
		$("#rtnData").text(JSON.stringify(data));
		
		/* //价格颜色变红：div.innerHTML(javaScript写法)
		$("#itemPrice").text("商品价格："+data[0].p);
		$("#itemId").text("商品编号："+data[0].id.substring(2)); */
		
		//价格颜色变红：div.innerHTML(javaScript写法)
		$("#itemPrice").html("商品价格：<font color='red'>"+data[0].p+"</font>");
		$("#itemId").text("商品编号："+data[0].id.substring(2));
	</script>


</html>
